package com.outfood.api.controller;

import com.outfood.common.common.response.CommonPage;
import com.outfood.common.common.response.RestResponse;
import com.outfood.domain.Order;
import com.outfood.service.IOrderService;
import com.rys.common.core.controller.BaseController;
import io.swagger.annotations.*;
import lombok.Data;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @Author huisonglin
 * @Description
 * @PackageName outfood-platform
 * @Package com.outfood.api.controller
 * @Date 2024-03-26 14:00
 * @Version 1.0
 */
@RestController
@Api(value = "OrderController" ,tags = {"订单相关操作类"})
@RequestMapping("/api/order")
public class OrderController extends BaseController {

    @Resource
    IOrderService orderService;

    @ApiOperation("获取门店列表")
    @GetMapping("getOrderList")
    public RestResponse<CommonPage<OrderVO>> getOrderList(@ApiParam("页号")@RequestParam Integer pageNum, @ApiParam("每页条数")@RequestParam(defaultValue = "10") Integer pageSize,@ApiParam("门店ID")@RequestParam Long storeId){
        startPage();
        List<Order> orderList = orderService.getOrderList(storeId);
        CommonPage optiontPreeCommonPage = CommonPage.restPage(orderList);
        List<OrderVO> orderVOs = new ArrayList<>();
        orderList.forEach(order -> {
            OrderVO orderVO = new OrderVO();
            BeanUtils.copyProperties(order,orderVO);
            orderVOs.add(orderVO);
        });
        optiontPreeCommonPage.setRows(orderVOs);
        return RestResponse.toPageData(optiontPreeCommonPage);
    }

    @Data
    @ApiModel("返回门店订单")
    public static class OrderVO{
        /**
         * 主键ID
         */
        @ApiModelProperty("主键ID")
        private Long id;

        @ApiModelProperty("订单编号")
        private String orderNo;

        /**
         * 餐品名称
         */
        @ApiModelProperty("餐品名称")
        private String foodName;

        /**
         * 购买人
         */
        @ApiModelProperty("购买人")
        private String buyerName;

        /**
         * 骑手
         */
        @ApiModelProperty("骑手")
        private String rider;

        /**
         * 预计收入
         */
        @ApiModelProperty("预计收入")
        private String income;

        /**
         * 第三方订单号
         */
        private String outTradeNo;

        private String poiId;

        /**
         * 订单创建时间
         */
        @ApiModelProperty("订单创建时间")
        private Date orderTime;

        /**
         * 确认时间
         */
        @ApiModelProperty("确认时间")
        private Date confirmTime;

        /**
         * 出餐时间
         */
        @ApiModelProperty("出餐时间")
        private Date outFoodTime;

        /**
         * 商家ID
         */
        private Long storeId;

        /**
         * 理论出餐时间
         */
        @ApiModelProperty("理论出餐时间")
        private Date theoryOutTime;

        /**
         * 出餐状态 OUTED  READY
         */
        @ApiModelProperty(" 出餐状态 OUTED  READY")
        private String outStatus;

        /**
         * create_user
         */
        private String createUser;

        /**
         * create_date
         */
        private Date createDate;

        /**
         * modify_user
         */
        private String modifyUser;

        /**
         * modify_date
         */
        private Date modifyDate;

        /**
         * state
         */
        private String state;
    }
}
